package thread;

/**
 * 当一个线程调用sleep方法
 */
public class SleepDemo2 {
    public static void main(String[] args) {
        Thread lin = new Thread("小嘉诚"){
            public  void run(){
                System.out.println(getName() + ":饿了去厕所吃一口");
            try{
                Thread.sleep(10000000);
            }catch (InterruptedException e){
                System.out.println(getName() + ":不是你有病啊！我还没吃饱");
            }
                System.out.println(getName() + ":吃饱了，再去旁边喝点");
            }
        };
        Thread YY = new Thread("盈盈"){
            public void run(){
                System.out.println(getName() + ":嘉诚!你别吃了");
                for (int i = 0; i < 5; i++){
                    System.out.println(getName() + ":快别吃了");
                    try {
                        Thread.sleep(1000);
                    }catch (InterruptedException e){}
                }
                System.out.println(getName() +":劝不动了");
                System.out.println(getName() +":太难劝了");
                lin.interrupt();
            }
        };
        lin.start();
        YY.start();
    }
}
